package com.acwing.partition9;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/11/30 20:43
 */
public class AC826单链表 {
    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split(" ");
        int m = Integer.parseInt(s[0]);
        SingleLinkedList singleLinkedList = new SingleLinkedList();
        while (m-- > 0) {
            s = reader.readLine().split(" ");
            if ("H".equals(s[0])) {
                int x = Integer.parseInt(s[1]);
                singleLinkedList.addToFirst(x);
            } else if ("D".equals(s[0])) {
                int k = Integer.parseInt(s[1]);
                singleLinkedList.remove(k - 1);
            } else {
                int k = Integer.parseInt(s[1]), x = Integer.parseInt(s[2]);
                singleLinkedList.add(k - 1, x);
            }
        }
        singleLinkedList.show();
    }

    private static class SingleLinkedList {
        private int head = -1;
        private int[] element = new int[1000];
        private int[] next = new int[1000];
        private int index = 0;

        public void addToFirst(int x) {
            element[index] = x;
            next[index] = head;
            head = index++;
        }

        public void add(int i, int x) {
            element[index] = x;
            next[index] = next[i];
            next[i] = index++;
        }

        public void remove(int i) {
            //删除i位置后面的一个结点
            if (i == -1) head = next[head];
            else next[i] = next[next[i]];
        }

        public void show() throws IOException {
            for (int i = head; i != -1; i = next[i]) writer.write(element[i] + " ");
            writer.write("\n");
            writer.flush();
        }
    }
}
